package cn.nohan.funplay.module.member.mongo.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.nohan.funplay.module.member.mongo.entity.MongoUserTrajectoryEntity;
import cn.nohan.funplay.module.member.mongo.mapper.MongoUserTrajectoryEntityMapper;
import com.mongoplus.aggregate.AggregateWrapper;
import com.mongoplus.conditions.query.QueryWrapper;
import com.mongoplus.model.PageParam;
import com.mongoplus.model.PageResult;
import com.mongoplus.toolkit.Filters;
import org.bson.conversions.Bson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author caozhipeng
 * @date 2025/8/1
 */
@Service
public class UserTrajectoryService {

    @Autowired
    private MongoUserTrajectoryEntityMapper mongoUserTrajectoryEntityMapper;


    public List<MongoUserTrajectoryEntity> findNearbyUsers(double maxDistance,double minDistance) {
        double x = 120.89415521913256d;
        double y = 31.971742189424283d;

        Bson filters = Filters.near("location",x,y,maxDistance,minDistance);

        AggregateWrapper aggregateWrapper = new AggregateWrapper();
        aggregateWrapper.addFields(filters);
        // 3. 执行查询
        PageParam pageParam=new PageParam(1,3);
        List<MongoUserTrajectoryEntity> results = mongoUserTrajectoryEntityMapper.getBaseMapper().aggregateList(aggregateWrapper,MongoUserTrajectoryEntity.class);
        return results;
    }
}
